package com.lw.spring.service.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author Administrator
 * @version 1.0
 * @description:
 * @date 2022/3/6 21:19
 */
public class MyAroundAdvice implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        System.out.println("开启了事务");
        System.out.println("校验了参数");
        //放行
        try {
            Object result = invocation.proceed();//执行原始方法
            System.out.println("提交事务");
            System.out.println("写入日志");
            return result;
        } catch (Throwable e) {
            e.printStackTrace();
            System.out.println("回滚事务");
        }
        return null;
    }
}
